package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.AnnualWorkDays;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.IndicatorSix;
import com.ruoyi.business.service.IIndicatorSixService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 指标六Controller
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/business/indicatorSix")
public class IndicatorSixController extends BaseController
{
    @Autowired
    private IIndicatorSixService indicatorSixService;

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    @ApiOperation(value = "导入全年出班天数数据", notes = "支持更新已有数据")
    public AjaxResult importData(
            @ApiParam(value = "上传的Excel文件", required = true) MultipartFile file,
            @ApiParam(value = "是否更新已有数据", required = true) boolean updateSupport) throws Exception
    {
        ExcelUtil<IndicatorSix> util = new ExcelUtil<IndicatorSix>(IndicatorSix.class);
        List<IndicatorSix> userList = util.importExcel("指标数据六",file.getInputStream(),1);
        String operName = getUsername();
        String message = indicatorSixService.importData(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    @ApiOperation(value = "导出全年出班天数数据模板", notes = "提供Excel模板用于导入")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<IndicatorSix> util = new ExcelUtil<IndicatorSix>(IndicatorSix.class);
        util.importTemplateExcel(response, "指标数据六","指标数据六");
    }

    /**
     * 查询指标六列表
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorSix:list')")
    @GetMapping("/list")
    public TableDataInfo list(IndicatorSix indicatorSix)
    {
        startPage();
        List<IndicatorSix> list = indicatorSixService.selectIndicatorSixList(indicatorSix);
        return getDataTable(list);
    }

    /**
     * 导出指标六列表
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorSix:export')")
    @Log(title = "指标六", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IndicatorSix indicatorSix)
    {
        List<IndicatorSix> list = indicatorSixService.selectIndicatorSixList(indicatorSix);
        ExcelUtil<IndicatorSix> util = new ExcelUtil<IndicatorSix>(IndicatorSix.class);
        util.exportExcel(response, list, "指标六数据");
    }

    /**
     * 获取指标六详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorSix:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(indicatorSixService.selectIndicatorSixById(id));
    }

    /**
     * 新增指标六
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorSix:add')")
    @Log(title = "指标六", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndicatorSix indicatorSix)
    {
        return toAjax(indicatorSixService.insertIndicatorSix(indicatorSix));
    }

    /**
     * 修改指标六
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorSix:edit')")
    @Log(title = "指标六", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndicatorSix indicatorSix)
    {
        return toAjax(indicatorSixService.updateIndicatorSix(indicatorSix));
    }

    /**
     * 删除指标六
     */
    @PreAuthorize("@ss.hasPermi('business:IndicatorSix:remove')")
    @Log(title = "指标六", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(indicatorSixService.deleteIndicatorSixByIds(ids));
    }
}
